package com.bitsemart.dialogos;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import com.bitsemart.R;

/**
 * Created by Adrian on 15/05/2015.
 */
public class SortDialogFragment extends DialogFragment {
    static String [] options;
    static int sortOption = 0;
    private ISortDialogFragment myISDF;


    public static String getSortOption() {
        if (options == null) return "Nombre";
        return options[sortOption];
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        super.onCreateDialog(savedInstanceState);
        options = getResources().getStringArray(R.array.sort_options);

        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.action_sort)
                .setSingleChoiceItems(R.array.sort_options, sortOption, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        sortOption = which;
                        dialog.dismiss();
                        myISDF.onSortCriteriaChange(SortDialogFragment.this);
                    }
                });
        // Create the AlertDialog object and return it
        return builder.create();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        myISDF = (ISortDialogFragment) activity;
    }
}
